package com.neusoft.elm.service;

import com.neusoft.elm.dao.DeliveryAddressDao;
import com.neusoft.elm.po.DeliveryAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeliveryAddressServiceImpl implements DeliveryAddressService{

    @Autowired
    private DeliveryAddressDao deliveryAddressDao;
    @Override
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        try {
            List<DeliveryAddress> list1 = deliveryAddressDao.listDeliveryAddressByUserId(userId);
            return list1;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
@Transactional(rollbackFor = Exception.class)
    @Override
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) {
        try {
            int i = deliveryAddressDao.saveDeliveryAddress(deliveryAddress);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
@Transactional(rollbackFor = Exception.class)
    @Override
    public int removeDeliveryAddress(Integer daId) {
        try {
            int i = deliveryAddressDao.removeDeliveryAddress(daId);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @Override
    public DeliveryAddress getDeliveryAddressById(Integer daId) {
        try {
            DeliveryAddress dA = deliveryAddressDao.getDeliveryAddressById(daId);
            return dA;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
@Transactional(rollbackFor = Exception.class)
    @Override
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) {
        try {
            int i = deliveryAddressDao.updateDeliveryAddress(deliveryAddress);
            return i;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }
}